﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRasta.Configuration;
using uREST.Core.Services;
using uREST.Core.Resources;
using uREST.Blog.Resources;
using uREST.Core;
using uREST.Blog.Handlers;
using uREST.Core.Codecs;
using OpenRasta.Web;

namespace uREST.Blog.Services
{
    public class CommentService : IuRESTService
    {
        public EndPoint EndPoint
        {
            get
            {
                return new EndPoint
                {
                    Name = "Comment Service",
                    Description = "",
                    Href = typeof(List<Comment>).CreateUri("CommentList").ToString()
                };
            }
        }

        public void RegisterHandlers()
        {
            ResourceSpace.Has.ResourcesOfType<List<Comment>>()
                .AtUri(uRESTConfig.BaseUrl + "/comments").Named("CommentList")
                .And.AtUri(uRESTConfig.BaseUrl + "/blogs/{blogId}/comments").Named("CommentList")
                .And.AtUri(uRESTConfig.BaseUrl + "/posts/{postId}/comments").Named("CommentList")
                .HandledBy<CommentHandler>()
                .TranscodedBy<JsonNetCodec>();

            ResourceSpace.Has.ResourcesOfType<Comment>()
                .AtUri(uRESTConfig.BaseUrl + "/comments/{id}").Named("Comment")
                .And.AtUri(uRESTConfig.BaseUrl + "/comments/{id}?permanent={permanent}").Named("Comment")
                .HandledBy<CommentHandler>()
                .TranscodedBy<JsonNetCodec>();
        }
    }
}
